//
//  MBSpaceSetUpNewDetailViewController.m
//  MiBaoTu
//
//  Created by admin on 16/9/23.
//  Copyright © 2016年 com.caesartech15. All rights reserved.
//

#import "MBSpaceSetUpNewDetailViewController.h"
#import "MBSpaceAddMusicViewController.h"
#import "MBSpaceChangeAlbumNameViewController.h"

#import "SharePLayerView.h"

@interface MBSpaceSetUpNewDetailViewController ()<SharePLayerViewDelegate> {
    UIView                  *topView;
    UILabel                 *_nickNameLb;
    UILabel                 *_userDetailLb;
    UIButton                *_loginBt;
}

@end

@implementation MBSpaceSetUpNewDetailViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self onUpdateUIForView:self.orientation];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setNavBar];
    [self onCreateUI];
}

#pragma mark - Actions
#pragma mark - UI
- (void)setNavBar
{
    if (_dataDic) {
        NSString *title = [_dataDic objectForKey:@"CateName"];
        [self setTitleView:title];
    } else {
        [self setTitleView:@"我的新分类"];
    }
    [self setBackItem];
    
    UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
    bt.frame = CGRectMake(0, 0, 60, 30);
    [bt setTitle:@"更多" forState:UIControlStateNormal];
    [bt setTitle:@"更多" forState:UIControlStateHighlighted];
    [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bt setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    bt.titleLabel.font = [UIFont systemFontOfSize:13.f];
    [bt setTitleEdgeInsets:UIEdgeInsetsMake(0, 30, 0, 0)];
    [bt addTarget:self action:@selector(onSelectItemForMore) forControlEvents:UIControlEventTouchUpInside];
    [self setRightBarItems:bt];
}

- (void)onCreateUI
{
    //背景
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, (WIDTH_5S ? (SCREEN_HEIGHT+NAV_HEIGHT-200)/2. : NAV_HEIGHT+490*PERCEN), SCREEN_WIDTH, 200)];
    if (!ISIPAD) {
        topView.centery = self.view.centery;
    }
    topView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:topView];
    
    _nickNameLb = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, topView.width, 20)];
    _nickNameLb.backgroundColor = [UIColor clearColor];
    _nickNameLb.textAlignment = NSTextAlignmentCenter;
    _nickNameLb.textColor = UIColorFromHex(0x333333);
    _nickNameLb.font = [UIFont systemFontOfSize:14.f];
    _nickNameLb.text = @"这个分类里面没有歌曲";
    [topView addSubview:_nickNameLb];
    
    _userDetailLb = [[UILabel alloc]initWithFrame:CGRectMake(_nickNameLb.left, _nickNameLb.bottom+20*PERCEN, _nickNameLb.width, 20)];
    _userDetailLb.backgroundColor = [UIColor clearColor];
    _userDetailLb.textAlignment = NSTextAlignmentCenter;
    _userDetailLb.textColor = UIColorFromHex(0x999999);
    _userDetailLb.font = [UIFont systemFontOfSize:13.f];
    _userDetailLb.text = @"你可以挑一些歌曲添加到这里";
    [topView addSubview:_userDetailLb];
    
    _loginBt = [UIButton buttonWithType:UIButtonTypeCustom];
    _loginBt.frame = CGRectMake((topView.width-(ISIPAD?700*PERCEN:360*PERCEN))/2., _userDetailLb.bottom+80*PERCEN, (ISIPAD?700*PERCEN:360*PERCEN), (ISIPAD?100*PERCEN:80*PERCEN));
    _loginBt.layer.cornerRadius = 5.f;
    _loginBt.layer.masksToBounds = YES;
    _loginBt.layer.borderWidth = 1.f;
    _loginBt.layer.borderColor = UIColorFromHex(0xeb6fa7).CGColor;
    _loginBt.backgroundColor = RGBCOLOR(228, 85, 150);
    [_loginBt setTitle:@"添加歌曲" forState:UIControlStateNormal];
    [_loginBt setTitle:@"添加歌曲" forState:UIControlStateHighlighted];
    [_loginBt setTitleColor:UIColorFromHex(0xffffff) forState:UIControlStateNormal];
    [_loginBt setTitleColor:UIColorFromHex(0xffffff) forState:UIControlStateHighlighted];
    _loginBt.titleLabel.font = [UIFont systemFontOfSize:14.f];
    [_loginBt addTarget:self action:@selector(onAddMusicAction) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:_loginBt];
}

- (void)onUpdateUIForView:(UIDeviceOrientation)orientation
{
    if (ISIPAD) {
        topView.frame = CGRectMake(0, (WIDTH_5S ? (SCREEN_HEIGHT+NAV_HEIGHT-200)/2. : NAV_HEIGHT+490*PERCEN), SCREEN_WIDTH, 200);
    } else {
        topView.frame = CGRectMake(0, (WIDTH_5S ? (SCREEN_HEIGHT+NAV_HEIGHT-200)/2. : NAV_HEIGHT+490*PERCEN), SCREEN_WIDTH, 200);
        topView.centery = SCREEN_HEIGHT/2.;
    }
    _nickNameLb.frame = CGRectMake(0, 0, topView.width, 20);
    _userDetailLb.frame = CGRectMake(_nickNameLb.left, _nickNameLb.bottom+20*PERCEN, _nickNameLb.width, 20);
    _loginBt.frame = CGRectMake((topView.width-(ISIPAD?700*PERCEN:360*PERCEN))/2., _userDetailLb.bottom+80*PERCEN, (ISIPAD?700*PERCEN:360*PERCEN), (ISIPAD?100*PERCEN:80*PERCEN));
}

#pragma mark - 更多操作-重命名、添加歌曲
- (void)onSelectItemForMore
{
    SharePLayerView *show = [[SharePLayerView alloc]initWithFrame:CGRectZero withType:ShowPlayerType_AddNewMusic];
    show.delegate = self;
    show.orientation = self.orientation;
    [show onShowInWindow];
}
//重命名
- (void)onSelctItemForMoreChangeNewMusicName:(SharePLayerView *)view
{
    if (!_dataDic) return;
    
    NSString *cateId = [_dataDic objectForKey:@"CateID"];
    if (cateId) {
        MBSpaceChangeAlbumNameViewController *changeName = [[MBSpaceChangeAlbumNameViewController alloc]init];
        changeName.dataDic = _dataDic;
        [self.navigationController pushViewController:changeName animated:YES];
    }
}
//添加歌曲
- (void)onSelctItemForMoreAddMusic:(SharePLayerView *)view
{
    MBSpaceAddMusicViewController *addMusic = [[MBSpaceAddMusicViewController alloc]init];
    addMusic.dataDic = _dataDic;
    addMusic.type = MBSpaceAddMusicType_SetAlbum;
    [self.navigationController pushViewController:addMusic animated:YES];
}

// 按钮-添加歌曲
- (void)onAddMusicAction
{
    MBSpaceAddMusicViewController *addMusic = [[MBSpaceAddMusicViewController alloc]init];
    addMusic.type = MBSpaceAddMusicType_SetAlbum;
    addMusic.dataDic = _dataDic;
    [self.navigationController pushViewController:addMusic animated:YES];
}

- (void)back
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
